package com.wejoy.video.middle.station.admin.controller.common;

import com.wejoy.video.middle.station.data.enums.dict.EnumGlobalContentType;
import com.wejoy.video.middle.station.data.vo.RespJSON;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * APP内链
 *
 * @author admin
 */
@RestController
@RequestMapping("/common/appLink")
public class AppLinkController {

    /**
     * 内链列表
     *
     * @return 返回的是级联显示数据结构
     */
    @RequestMapping("/list")
    public RespJSON list() {
        EnumGlobalContentType[] values = EnumGlobalContentType.values();
        List<Map<String, Object>> list = Arrays.stream(values)
                .filter(item -> item.getShow())
                .map(item -> {
                    Map<String, Object> map = new HashMap<>(5);
                    map.put("code", item.getCode() + "");
                    map.put("text", item.getText());
                    map.put("url", item.getUrl());
                    map.put("chooseDataUrl", item.getChooseDataUrl());
                    map.put("leaf", StringUtils.isEmpty(item.getChooseDataUrl()));
                    return map;
                }).collect(Collectors.toList());
        return RespJSON.success(list);
    }
}
